<template>
   <div class="pro_con2">
    <el-card class="box-card1">
      <div class="clearfix1">
        <span><i class="iconfont icon-dingdan11"></i>商品类型</span>
        <el-button style="float: right" type="primary" size="small" @click="goadd2">添加</el-button>
      </div>
    </el-card>

    <el-table :data="attrList" border style="width: 100%" :cell-style="{textAlign:'center'}" :header-cell-style="{'text-align':'center'}">
      <el-table-column prop="id" label="编号" width="180"> </el-table-column>
      <el-table-column prop="name" label="类型名称" width="180">
      </el-table-column>
      <el-table-column prop="attribute_count" label="属性数量">
      </el-table-column>
      <el-table-column prop="param_count" label="参数数量"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button  type="primary" size="mini"   @click="updateProduct(scope.row.id)">修改</el-button>
          <el-button type="danger" size="mini" @click="delProduct(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.pageNum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="listQuery.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
import {fetchProductAttrList} from '@/api/product.js';
export default {
    name:'prouctAttr',
    data:function(){
      return{
        attrList:[],
        listQuery:{
          pageSize:5,
          pegaNum:1
        },
        total:0,
      }
    },
    methods:{
    getProductList(){
      fetchProductAttrList(this.listQuery).then((res)=>{
        console.log(res);
        this.attrList = res.data;
        this.total=res.total;
      })
    },
    handleSizeChange(val) {
      console.log("修改页面条数的函数运行了", val);
      this.listQuery.pageSize = val;
      
      this.listQuery.pageNum = val;
      //获取数据
      this.getProductList();
    },
    handleCurrentChange(val) {
      console.log("修改当前页的页码的函数运行了", val);
      //将页码信息 保存到  listQuery
      this.listQuery.pageNum = val;
      //再次获取数据
      this.getProductList();
    },
    goadd2:function(){
      this.$router.push('/pms/productAttrAdd')
    },
    updateProduct: function (id) {
      console.log(id);
      this.$router.push("/pms/productAttrupdate/"+row.id+"/"+row.name);
    },
    //删除的函数
    delProduct: function (id) {
      console.log(id);
      //1.删除前需要提示
      this.$confirm("此操作将永久删除该条商品数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delProduct({ id: id }).then((res) => {
            console.log(res);
            if (res.type == "success") {
              this.$message({
                type: "success",
                message: "删除成功!",
                duration: 2000,
              });
              //2.删除后需要刷新数据
              //重新获取数据
              this.getProductList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
            duration: 2000,
          });
        });
    },
  },
  created(){
    this.getProductList()
  },
    
}
</script>
<style  lang="scss">

</style>